﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwArtiklTraziProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwArtiklTraziProviderBaseCore : EntityViewProviderBase<VwArtiklTrazi>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwArtiklTrazi&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwArtiklTrazi&gt;"/></returns>
		protected static VList&lt;VwArtiklTrazi&gt; Fill(DataSet dataSet, VList<VwArtiklTrazi> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwArtiklTrazi>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwArtiklTrazi&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwArtiklTrazi>"/></returns>
		protected static VList&lt;VwArtiklTrazi&gt; Fill(DataTable dataTable, VList<VwArtiklTrazi> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwArtiklTrazi c = new VwArtiklTrazi();
					c.ID = (Convert.IsDBNull(row["ID"]))?(int)0:(System.Int32)row["ID"];
					c.Naziv = (Convert.IsDBNull(row["Naziv"]))?string.Empty:(System.String)row["Naziv"];
					c.BarCode = (Convert.IsDBNull(row["BarCode"]))?string.Empty:(System.String)row["BarCode"];
					c.Mjera = (Convert.IsDBNull(row["Mjera"]))?string.Empty:(System.String)row["Mjera"];
					c.Porez = (Convert.IsDBNull(row["Porez"]))?string.Empty:(System.String)row["Porez"];
					c.StopaPoreza = (Convert.IsDBNull(row["StopaPoreza"]))?0.0F:(System.Single?)row["StopaPoreza"];
					c.ImeKlijenta = (Convert.IsDBNull(row["ImeKlijenta"]))?string.Empty:(System.String)row["ImeKlijenta"];
					c.Kategorija = (Convert.IsDBNull(row["Kategorija"]))?string.Empty:(System.String)row["Kategorija"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwArtiklTrazi&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwArtiklTrazi&gt;"/></returns>
		protected VList<VwArtiklTrazi> Fill(IDataReader reader, VList<VwArtiklTrazi> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwArtiklTrazi entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwArtiklTrazi>("VwArtiklTrazi",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwArtiklTrazi();
					}
					entity.ID = (System.Int32)reader["ID"];
					//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
					entity.Naziv = (System.String)reader["Naziv"];
					//entity.Naziv = (Convert.IsDBNull(reader["Naziv"]))?string.Empty:(System.String)reader["Naziv"];
					entity.BarCode = reader.IsDBNull(reader.GetOrdinal("BarCode")) ? null : (System.String)reader["BarCode"];
					//entity.BarCode = (Convert.IsDBNull(reader["BarCode"]))?string.Empty:(System.String)reader["BarCode"];
					entity.Mjera = reader.IsDBNull(reader.GetOrdinal("Mjera")) ? null : (System.String)reader["Mjera"];
					//entity.Mjera = (Convert.IsDBNull(reader["Mjera"]))?string.Empty:(System.String)reader["Mjera"];
					entity.Porez = reader.IsDBNull(reader.GetOrdinal("Porez")) ? null : (System.String)reader["Porez"];
					//entity.Porez = (Convert.IsDBNull(reader["Porez"]))?string.Empty:(System.String)reader["Porez"];
					entity.StopaPoreza = reader.IsDBNull(reader.GetOrdinal("StopaPoreza")) ? null : (System.Single?)reader["StopaPoreza"];
					//entity.StopaPoreza = (Convert.IsDBNull(reader["StopaPoreza"]))?0.0F:(System.Single?)reader["StopaPoreza"];
					entity.ImeKlijenta = reader.IsDBNull(reader.GetOrdinal("ImeKlijenta")) ? null : (System.String)reader["ImeKlijenta"];
					//entity.ImeKlijenta = (Convert.IsDBNull(reader["ImeKlijenta"]))?string.Empty:(System.String)reader["ImeKlijenta"];
					entity.Kategorija = reader.IsDBNull(reader.GetOrdinal("Kategorija")) ? null : (System.String)reader["Kategorija"];
					//entity.Kategorija = (Convert.IsDBNull(reader["Kategorija"]))?string.Empty:(System.String)reader["Kategorija"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwArtiklTrazi"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwArtiklTrazi"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwArtiklTrazi entity)
		{
			reader.Read();
			entity.ID = (System.Int32)reader["ID"];
			//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
			entity.Naziv = (System.String)reader["Naziv"];
			//entity.Naziv = (Convert.IsDBNull(reader["Naziv"]))?string.Empty:(System.String)reader["Naziv"];
			entity.BarCode = reader.IsDBNull(reader.GetOrdinal("BarCode")) ? null : (System.String)reader["BarCode"];
			//entity.BarCode = (Convert.IsDBNull(reader["BarCode"]))?string.Empty:(System.String)reader["BarCode"];
			entity.Mjera = reader.IsDBNull(reader.GetOrdinal("Mjera")) ? null : (System.String)reader["Mjera"];
			//entity.Mjera = (Convert.IsDBNull(reader["Mjera"]))?string.Empty:(System.String)reader["Mjera"];
			entity.Porez = reader.IsDBNull(reader.GetOrdinal("Porez")) ? null : (System.String)reader["Porez"];
			//entity.Porez = (Convert.IsDBNull(reader["Porez"]))?string.Empty:(System.String)reader["Porez"];
			entity.StopaPoreza = reader.IsDBNull(reader.GetOrdinal("StopaPoreza")) ? null : (System.Single?)reader["StopaPoreza"];
			//entity.StopaPoreza = (Convert.IsDBNull(reader["StopaPoreza"]))?0.0F:(System.Single?)reader["StopaPoreza"];
			entity.ImeKlijenta = reader.IsDBNull(reader.GetOrdinal("ImeKlijenta")) ? null : (System.String)reader["ImeKlijenta"];
			//entity.ImeKlijenta = (Convert.IsDBNull(reader["ImeKlijenta"]))?string.Empty:(System.String)reader["ImeKlijenta"];
			entity.Kategorija = reader.IsDBNull(reader.GetOrdinal("Kategorija")) ? null : (System.String)reader["Kategorija"];
			//entity.Kategorija = (Convert.IsDBNull(reader["Kategorija"]))?string.Empty:(System.String)reader["Kategorija"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwArtiklTrazi"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwArtiklTrazi"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwArtiklTrazi entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.ID = (Convert.IsDBNull(dataRow["ID"]))?(int)0:(System.Int32)dataRow["ID"];
			entity.Naziv = (Convert.IsDBNull(dataRow["Naziv"]))?string.Empty:(System.String)dataRow["Naziv"];
			entity.BarCode = (Convert.IsDBNull(dataRow["BarCode"]))?string.Empty:(System.String)dataRow["BarCode"];
			entity.Mjera = (Convert.IsDBNull(dataRow["Mjera"]))?string.Empty:(System.String)dataRow["Mjera"];
			entity.Porez = (Convert.IsDBNull(dataRow["Porez"]))?string.Empty:(System.String)dataRow["Porez"];
			entity.StopaPoreza = (Convert.IsDBNull(dataRow["StopaPoreza"]))?0.0F:(System.Single?)dataRow["StopaPoreza"];
			entity.ImeKlijenta = (Convert.IsDBNull(dataRow["ImeKlijenta"]))?string.Empty:(System.String)dataRow["ImeKlijenta"];
			entity.Kategorija = (Convert.IsDBNull(dataRow["Kategorija"]))?string.Empty:(System.String)dataRow["Kategorija"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwArtiklTraziFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwArtiklTrazi"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwArtiklTraziFilterBuilder : SqlFilterBuilder<VwArtiklTraziColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwArtiklTraziFilterBuilder class.
		/// </summary>
		public VwArtiklTraziFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklTraziFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwArtiklTraziFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklTraziFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwArtiklTraziFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwArtiklTraziFilterBuilder

	#region VwArtiklTraziParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwArtiklTrazi"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwArtiklTraziParameterBuilder : ParameterizedSqlFilterBuilder<VwArtiklTraziColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwArtiklTraziParameterBuilder class.
		/// </summary>
		public VwArtiklTraziParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklTraziParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwArtiklTraziParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwArtiklTraziParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwArtiklTraziParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwArtiklTraziParameterBuilder
} // end namespace
